from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-07-18 14:10:36.505646
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 18, Jul, 2022
Time: 14:10:42
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.8407
Nobs: 721.000 HQIC: -50.1918
Log likelihood: 9056.22 FPE: 1.27681e-22
AIC: -50.4125 Det(Omega_mle): 1.12794e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299575 0.057063 5.250 0.000
L1.Burgenland 0.106889 0.037385 2.859 0.004
L1.Kärnten -0.107068 0.019825 -5.401 0.000
L1.Niederösterreich 0.210687 0.078338 2.689 0.007
L1.Oberösterreich 0.106414 0.076465 1.392 0.164
L1.Salzburg 0.253915 0.040005 6.347 0.000
L1.Steiermark 0.042152 0.052201 0.807 0.419
L1.Tirol 0.108706 0.042326 2.568 0.010
L1.Vorarlberg -0.063860 0.036565 -1.746 0.081
L1.Wien 0.047831 0.067585 0.708 0.479
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054719 0.119240 0.459 0.646
L1.Burgenland -0.031426 0.078121 -0.402 0.687
L1.Kärnten 0.047027 0.041427 1.135 0.256
L1.Niederösterreich -0.178489 0.163697 -1.090 0.276
L1.Oberösterreich 0.412368 0.159783 2.581 0.010
L1.Salzburg 0.288849 0.083596 3.455 0.001
L1.Steiermark 0.106843 0.109081 0.979 0.327
L1.Tirol 0.311769 0.088444 3.525 0.000
L1.Vorarlberg 0.026132 0.076407 0.342 0.732
L1.Wien -0.030637 0.141227 -0.217 0.828
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.188256 0.029150 6.458 0.000
L1.Burgenland 0.089937 0.019098 4.709 0.000
L1.Kärnten -0.008872 0.010128 -0.876 0.381
L1.Niederösterreich 0.262912 0.040019 6.570 0.000
L1.Oberösterreich 0.138002 0.039062 3.533 0.000
L1.Salzburg 0.046212 0.020436 2.261 0.024
L1.Steiermark 0.020052 0.026667 0.752 0.452
L1.Tirol 0.092703 0.021622 4.287 0.000
L1.Vorarlberg 0.056493 0.018679 3.024 0.002
L1.Wien 0.115479 0.034525 3.345 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111321 0.029656 3.754 0.000
L1.Burgenland 0.045434 0.019429 2.338 0.019
L1.Kärnten -0.013964 0.010303 -1.355 0.175
L1.Niederösterreich 0.190444 0.040713 4.678 0.000
L1.Oberösterreich 0.302072 0.039740 7.601 0.000
L1.Salzburg 0.109522 0.020791 5.268 0.000
L1.Steiermark 0.104061 0.027130 3.836 0.000
L1.Tirol 0.105136 0.021997 4.780 0.000
L1.Vorarlberg 0.067516 0.019003 3.553 0.000
L1.Wien -0.022101 0.035125 -0.629 0.529
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.130407 0.054084 2.411 0.016
L1.Burgenland -0.050353 0.035433 -1.421 0.155
L1.Kärnten -0.040961 0.018790 -2.180 0.029
L1.Niederösterreich 0.167047 0.074248 2.250 0.024
L1.Oberösterreich 0.141895 0.072473 1.958 0.050
L1.Salzburg 0.289224 0.037916 7.628 0.000
L1.Steiermark 0.035374 0.049476 0.715 0.475
L1.Tirol 0.162978 0.040116 4.063 0.000
L1.Vorarlberg 0.098265 0.034656 2.835 0.005
L1.Wien 0.068496 0.064056 1.069 0.285
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.055901 0.043058 1.298 0.194
L1.Burgenland 0.039312 0.028210 1.394 0.163
L1.Kärnten 0.051386 0.014960 3.435 0.001
L1.Niederösterreich 0.217011 0.059112 3.671 0.000
L1.Oberösterreich 0.295890 0.057698 5.128 0.000
L1.Salzburg 0.043734 0.030187 1.449 0.147
L1.Steiermark 0.001364 0.039389 0.035 0.972
L1.Tirol 0.142338 0.031938 4.457 0.000
L1.Vorarlberg 0.072532 0.027591 2.629 0.009
L1.Wien 0.081390 0.050997 1.596 0.110
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.175565 0.051435 3.413 0.001
L1.Burgenland -0.003018 0.033698 -0.090 0.929
L1.Kärnten -0.062492 0.017870 -3.497 0.000
L1.Niederösterreich -0.081896 0.070612 -1.160 0.246
L1.Oberösterreich 0.193235 0.068924 2.804 0.005
L1.Salzburg 0.057825 0.036060 1.604 0.109
L1.Steiermark 0.235505 0.047053 5.005 0.000
L1.Tirol 0.497583 0.038151 13.042 0.000
L1.Vorarlberg 0.043463 0.032959 1.319 0.187
L1.Wien -0.053246 0.060919 -0.874 0.382
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.174109 0.058989 2.952 0.003
L1.Burgenland -0.007479 0.038647 -0.194 0.847
L1.Kärnten 0.066412 0.020494 3.240 0.001
L1.Niederösterreich 0.209580 0.080982 2.588 0.010
L1.Oberösterreich -0.075443 0.079046 -0.954 0.340
L1.Salzburg 0.207829 0.041355 5.025 0.000
L1.Steiermark 0.122250 0.053963 2.265 0.023
L1.Tirol 0.070395 0.043754 1.609 0.108
L1.Vorarlberg 0.115332 0.037799 3.051 0.002
L1.Wien 0.119594 0.069866 1.712 0.087
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.361802 0.034029 10.632 0.000
L1.Burgenland 0.007142 0.022294 0.320 0.749
L1.Kärnten -0.023930 0.011823 -2.024 0.043
L1.Niederösterreich 0.217373 0.046716 4.653 0.000
L1.Oberösterreich 0.199741 0.045599 4.380 0.000
L1.Salzburg 0.043116 0.023857 1.807 0.071
L1.Steiermark -0.014756 0.031130 -0.474 0.635
L1.Tirol 0.105177 0.025240 4.167 0.000
L1.Vorarlberg 0.070382 0.021805 3.228 0.001
L1.Wien 0.036027 0.040303 0.894 0.371
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.040060 0.138379 0.191142 0.150503 0.117432 0.102263 0.061359 0.215899
Kärnten 0.040060 1.000000 -0.006398 0.133239 0.039106 0.094537 0.433749 -0.053765 0.098085
Niederösterreich 0.138379 -0.006398 1.000000 0.335203 0.140317 0.294633 0.095336 0.175604 0.313703
Oberösterreich 0.191142 0.133239 0.335203 1.000000 0.226671 0.325361 0.174308 0.164185 0.261438
Salzburg 0.150503 0.039106 0.140317 0.226671 1.000000 0.142233 0.110554 0.143522 0.123051
Steiermark 0.117432 0.094537 0.294633 0.325361 0.142233 1.000000 0.145610 0.136640 0.071021
Tirol 0.102263 0.433749 0.095336 0.174308 0.110554 0.145610 1.000000 0.109701 0.142331
Vorarlberg 0.061359 -0.053765 0.175604 0.164185 0.143522 0.136640 0.109701 1.000000 -0.001800
Wien 0.215899 0.098085 0.313703 0.261438 0.123051 0.071021 0.142331 -0.001800 1.000000